package com.thti.mecool.client.model.biz;

import java.util.List;

import android.content.Context;

import com.thti.mecool.client.db.DataBase;
import com.thti.mecool.client.model.po.ProjectServer;

public class ProjectServerBizImpl {
	private DataBase dataBase;

	public ProjectServerBizImpl(Context context) {
		dataBase = new DataBase(context);
	}
	
	public void save(ProjectServer projectServer){
		String sql="insert into projectServer(projectId,name,taskId,storeId,isType,requiredCount,finishedCount,criticalJob) values(?,?,?,?,?,?,?,?)";
	     dataBase
	     .execObject(sql, new Object[]{projectServer.getProjectId(),projectServer.getName(),projectServer.getTaskId(),projectServer.getStoreId(),projectServer.getIsType()
	    		 ,projectServer.getRequiredCount(),projectServer.getFinishedCount(),projectServer.getCriticalJob()});
	     dataBase.close();
	}
	
	public List<ProjectServer>  findByProject(int isType){
		String sql="select * from projectServer where isType=? order by criticalJob desc";
		@SuppressWarnings("unchecked")
		List<ProjectServer> list=dataBase.findAll(ProjectServer.class, sql, new String[]{String.valueOf(isType)});
		return list;
		
	}
	
	public List<ProjectServer>  findBystore(String projectId,int isType){
		String sql="select * from projectServer where projectId=? and isType=?";
		@SuppressWarnings("unchecked")
		List<ProjectServer> list=dataBase.findAll(ProjectServer.class, sql, new String[]{projectId,String.valueOf(isType)});
		dataBase.close();
		return list;
		
	}
	
	public List<ProjectServer>  findByTask(){
		String sql="select * from projectServer where isType=1";
		@SuppressWarnings("unchecked")
		List<ProjectServer> list=dataBase.findAll(ProjectServer.class, sql, new String[]{});
		return list;
		
	}
	
	public void delete(){
		String sql="delete from projectServer";
		 dataBase
	     .execObject(sql, new String[]{});
	     dataBase.close();
	}
	
	public void deleteTask(){
		String sql="delete from projectServer where isType=1";
		 dataBase
	     .execObject(sql, new String[]{});
	     dataBase.close();
	}
}
